package kr.hkit.androidcomplete03.ETC;

import kr.hkit.androidcomplete03.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

public class SpinnerPosterTest extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main2);
		
		Gallery gallery = (Gallery) findViewById(R.id.galleryclick1);
		MyGalleryAdapter mAdapter = new MyGalleryAdapter(this);
		gallery.setAdapter(mAdapter);
		
	}
	
	public class MyGalleryAdapter extends BaseAdapter {
		Context context;
			
		public MyGalleryAdapter(Context context) {
			this.context = context;
		}

		Integer[] posterID = { R.drawable.mov01, R.drawable.mov02,
				R.drawable.mov03, R.drawable.mov04, R.drawable.mov05,
				R.drawable.mov06, R.drawable.mov07, R.drawable.mov08,
				R.drawable.mov09, R.drawable.mov10, R.drawable.mov11,
				R.drawable.mov12, R.drawable.mov13, R.drawable.mov14,
				R.drawable.mov15, R.drawable.mov16, R.drawable.mov17 };

		String[] posterNameID = { "써니", "완득이", "괴물", "라디오스타", "비열한 거리",
				"왕의 남자", "아일랜드", "웰컴투동막골", "헬보이", "백투더퓨쳐", "여인의 향기", "쥬라기공원",
				"포레스트검프", "제목몰라", "혹성탈출", "아름다운비행", "내이름은칸", };
		
		@Override
		public int getCount() {
			return posterID.length;
		}

		@Override
		public Object getItem(int arg0) {
			return null;
		}

		@Override
		public long getItemId(int arg0) {
			return 0;
		}

		@Override
		public View getView(int arg0, View arg1, ViewGroup arg2) {
			ImageView imageview = new ImageView(context);
			imageview.setLayoutParams(new Gallery.LayoutParams(100, 150));
			imageview.setScaleType(ImageView.ScaleType.FIT_CENTER);
			imageview.setPadding(5, 5, 5, 5);

			final int pos = arg0;
			imageview.setOnTouchListener(new View.OnTouchListener() {
				
				@Override
				public boolean onTouch(View arg0, MotionEvent arg1) {
					ImageView ivPoster = (ImageView) findViewById(R.id.ivposter2);
					ivPoster.setScaleType(ImageView.ScaleType.FIT_CENTER);
					ivPoster.setImageResource(posterID[pos]);
					return false;
				}
				
			});

			imageview.setImageResource(posterID[arg0]);
			return imageview;
		}
		
	}
}
